#include <bits/stdc++.h>
using namespace std;

int main() {
    int n, m, q, a, b, c, d;
    cin >> n >> m;
    int arr[n + 5][m + 5];
    for (int i = 1; i <= n; ++i)
        for (int j = 1; j <= m; ++j)
            cin >> arr[i][j];
    cin >> q;
    while (q--) {
        int ans = 0;
        cin >> a >> b >> c >> d;
        for (int i = a; i <= c; ++i)
            for (int j = b; j <= d; ++j)
                ans += arr[i][j];
        cout << ans << endl;
    }
    return 0;
}